﻿using System;
using System.Reflection;
using System.IO;

using IdeaNMR.Shared.Utils;

namespace IdeaNMR.Web.Core
{
    /// <summary>
    /// Dimensionality of experiment.
    /// </summary>
    /// <remarks>When changed check the DimentionalityExtensions.</remarks>
    public enum Dimensionality : byte
    {
        NotApplicable = 0,
        D1,
        D2,
        D3,
        D4
    }

    public static class DimentionalityExtensions
    {
        /// <summary>
        /// Makes 1D from D1 etc and Not Applicable from NotApplicable
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static string ToConventionalString(this Dimensionality d)
        {
            // Human readable form
            string[] dimArray = { "Not Applicable", "1D", "2D", "3D", "4D" };
            return dimArray[(int)d];
        }

        public static byte Parse(string str)
        {
            string[] dimArray = { "Not Applicable", "1D", "2D", "3D", "4D" };
            for (byte i = 1; i < dimArray.Length; i++)
            {
                if (str == dimArray[i])
                    return i;
            }
            return 0;
        }
    }

    public static class EmbeddedPythonScripts
    {
        public static string LoadScript(string fileName)
        {
            string fullName = "IdeaNMR.Web.Core.ExampleSetup." + fileName;
            return new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(fullName)).ReadToEnd().ToLocalNewLine();
        }
    }
}
